/*
 Xern Entity Relocation Network
 Copyright (C) 2010-2011 Ronie Salgado <roniesalg@gmail.com>

 Permission is hereby granted, free of charge, to any person obtaining a copy
 of this software and associated documentation files (the "Software"), to deal
 in the Software without restriction, including without limitation the rights
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 copies of the Software, and to permit persons to whom the Software is
 furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in
 all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 THE SOFTWARE.
*/

// Math classes are special.
%include "XernMath.i"


// Include all of Xern
%{
#include "Xern/DataTypes.hpp"

#include "Xern/IConsole.hpp"
#include "Xern/IClientModule.hpp"
#include "Xern/IDataFilter.hpp"
#include "Xern/IEntityFactory.hpp"
#include "Xern/IGeometry.hpp"
#include "Xern/IGeometryInstance.hpp"
#include "Xern/IGuiSystem.hpp"
#include "Xern/IInputListener.hpp"
#include "Xern/IInputSystem.hpp"
#include "Xern/IInterface.hpp"
#include "Xern/IMaterial.hpp"
#include "Xern/IMovableObject.hpp"
#include "Xern/IMovementListener.hpp"
#include "Xern/IParticleSystem.hpp"
#include "Xern/IPhysicsEngine.hpp"
#include "Xern/IRenderer.hpp"
#include "Xern/IResource.hpp"
#include "Xern/IResourceLoader.hpp"
#include "Xern/IRigidBody.hpp"
#include "Xern/ISerializableResource.hpp"
#include "Xern/ISceneNode.hpp"
#include "Xern/IScriptEngine.hpp"
#include "Xern/IScriptModule.hpp"
#include "Xern/IServerModule.hpp"
#include "Xern/ISoundSampler.hpp"
#include "Xern/ISoundSource.hpp"
#include "Xern/ISoundListener.hpp"
#include "Xern/ISoundEngine.hpp"
#include "Xern/ITexture.hpp"

#include "Xern/Console.hpp"
#include "Xern/Engine.hpp"
#include "Xern/Entity.hpp"
#include "Xern/Plugin.hpp"
#include "Xern/PluginRegistry.hpp"
#include "Xern/ResourceGroup.hpp"
#include "Xern/ResourceManager.hpp"
#include "Xern/Region.hpp"
#include "Xern/Exceptions.hpp"
#include "Xern/FileSystem.hpp"
#include "Xern/KeyCode.hpp"
#include "Xern/Hashes.hpp"
#include "Xern/Log.hpp"
#include "Xern/Singleton.hpp"
#include "Xern/WorldManager.hpp"

// Special classes.
#include "LogHooker.hpp"
#include "EntityFactory.hpp"
#include "EntityWrapper.hpp"

%}

// Declare the objects that use boost::shared_ptr.
%shared_ptr(Xern::IInterface);
%shared_ptr(Xern::IResource);
%shared_ptr(Xern::IMovableObject);

%shared_ptr(Xern::IBoxShape);
%shared_ptr(Xern::ICamera);
%shared_ptr(Xern::ICapsuleShape);
%shared_ptr(Xern::ICollisionShape);
%shared_ptr(Xern::ICompoundShape);
%shared_ptr(Xern::IConvexHullShape);
%shared_ptr(Xern::IConsole);
%shared_ptr(Xern::IConsoleVariable);
%shared_ptr(Xern::IConsoleCommand);
%shared_ptr(Xern::IClientModule);
%shared_ptr(Xern::IDataFilter);
%shared_ptr(Xern::IEntityFactory);
%shared_ptr(Xern::IGeometry);
%shared_ptr(Xern::IGeometryInstance);
%shared_ptr(Xern::IGuiSystem);
%shared_ptr(Xern::IInputListener);
%shared_ptr(Xern::IInputSystem);
%shared_ptr(Xern::ILight);
%shared_ptr(Xern::IMaterial);
%shared_ptr(Xern::IMovableObject);
%shared_ptr(Xern::IMovementListener);
%shared_ptr(Xern::IParticleSystem);
%shared_ptr(Xern::IPhysicRegion);
%shared_ptr(Xern::IPhysicsEngine);
%shared_ptr(Xern::IRenderer);
%shared_ptr(Xern::IResourceLoader);
%shared_ptr(Xern::IRigidBody);
%shared_ptr(Xern::ISerializableResource);
%shared_ptr(Xern::ISceneNode);
%shared_ptr(Xern::IScriptEngine);
%shared_ptr(Xern::IScriptModule);
%shared_ptr(Xern::IServerModule);
%shared_ptr(Xern::ISphereShape);
%shared_ptr(Xern::ISoundSampler);
%shared_ptr(Xern::ISoundEngine);
%shared_ptr(Xern::ISoundListener);
%shared_ptr(Xern::ISoundSource);
%shared_ptr(Xern::ITexture)

%shared_ptr(Xern::Console)
%shared_ptr(Xern::ConsoleVariable)
%shared_ptr(Xern::Entity);
%shared_ptr(Xern::Log);
%shared_ptr(Xern::PluginModule);
%shared_ptr(Xern::PluginRegistry);
%shared_ptr(Xern::ResourceManager);
%shared_ptr(Xern::Region);
%shared_ptr(Xern::WorldManager);

%shared_ptr(XernSquirrel::LogHooker);
%shared_ptr(XernSquirrel::EntityFactory);
%shared_ptr(XernSquirrel::EntityWrapper);

%ignore Xern::detail::MemberConsoleCommand;
%ignore Xern::BaseConsoleCommand;
%ignore Xern::ConsoleCommand;

// boost::enable_shared_from_this instances.
%template(EntitySharedFromThis) boost::enable_shared_from_this<Xern::Entity>;

// Data types.
%include "Xern/DataTypes.hpp"

// Singleton instances. 
%include "Xern/Singleton.hpp"
%template(EngineSingleton) Xern::Singleton<Xern::Engine>;

// Include the Xern core headers.
#define XERN_ALIGNED(x)

%include "Xern/IInterface.hpp"
%include "Xern/IMovableObject.hpp"
%include "Xern/IResource.hpp"
%include "Xern/ISerializableResource.hpp"

%include "Xern/ICamera.hpp"
%include "Xern/IConsole.hpp"
%include "Xern/ICollisionShape.hpp"
%include "Xern/IClientModule.hpp"
%include "Xern/IDataFilter.hpp"
%include "Xern/IEntityFactory.hpp"
%include "Xern/IGuiSystem.hpp"
%include "Xern/IGeometry.hpp"
%include "Xern/IGeometryInstance.hpp"
%include "Xern/IInputListener.hpp"
%include "Xern/IInputSystem.hpp"
%include "Xern/IInterface.hpp"
%include "Xern/ILight.hpp"
%include "Xern/IMaterial.hpp"
%include "Xern/IMovementListener.hpp"
%include "Xern/IMovableObject.hpp"
%include "Xern/IResourceLoader.hpp"
%include "Xern/IRigidBody.hpp"
%include "Xern/IParticleSystem.hpp"
%include "Xern/IPhysicRegion.hpp"
%include "Xern/IPhysicsEngine.hpp"
%include "Xern/ISceneNode.hpp"
%include "Xern/ITexture.hpp"
%include "Xern/IRenderer.hpp"
%include "Xern/IScriptEngine.hpp"
%include "Xern/IScriptModule.hpp"
%include "Xern/IServerModule.hpp"
%include "Xern/ISoundSampler.hpp"
%include "Xern/ISoundSource.hpp"
%include "Xern/ISoundListener.hpp"
%include "Xern/ISoundEngine.hpp"

%include "Xern/Console.hpp"
%include "Xern/Hashes.hpp"
%include "Xern/Log.hpp"

%include "Xern/KeyCode.hpp"
%include "Xern/Plugin.hpp"
%include "Xern/PluginRegistry.hpp"
%include "Xern/SystemDescription.hpp"
%include "Xern/Engine.hpp"
%include "Xern/Entity.hpp"
%include "Xern/Region.hpp"
%include "Xern/WorldManager.hpp"
%include "Xern/ResourceGroup.hpp"
%include "Xern/ResourceManager.hpp"

// Special classes.
%include "LogHooker.hpp"
%include "EntityFactory.hpp"
%include "EntityWrapper.hpp"

// Extra code for EntityFactory/EntityWrapper
%{
	boost::shared_ptr<Xern::Entity> XS_ExtractEntity(HSQUIRRELVM v, int idx)
	{
		boost::shared_ptr<Xern::Entity> ret;
		boost::shared_ptr<Xern::Entity> *smartarg = 0 ;
		
		assert(sqs_isinstance(v, idx));
		int newmem = 0;
		int res = SWIG_ConvertPtr(v,idx,(void**)&smartarg,SWIGTYPE_p_boost__shared_ptrT_Xern__Entity_t, 0, &newmem);
		assert(SWIG_IsOK(res));
    	if(newmem & SWIG_CAST_NEW_MEMORY)
    	{
      		assert(smartarg);
      		ret = *smartarg;
      		delete smartarg;    
    	}
    	else
    	{
    		if(smartarg) ret = *smartarg;
    	}
    
		return ret;
	}

	void XS_PushEntity(HSQUIRRELVM v, boost::shared_ptr<Xern::Entity> ent)
	{	
	    boost::shared_ptr<  Xern::Entity > *smartptr = ent ? new boost::shared_ptr<Xern::Entity> (ent SWIG_NO_NULL_DELETER_1) : 0;
    	SWIG_NewPointerObjSmart(v,(void*)smartptr,SWIGTYPE_p_boost__shared_ptrT_Xern__Entity_t, SWIGTYPE_p_Xern__Entity, SWIG_POINTER_OWN);
    }
%}

%define CAST_TO(target)
%{

	namespace Xern
	{
		boost::shared_ptr<target> CastTo ## target(boost::shared_ptr<IInterface> object)
		{
			return boost::dynamic_pointer_cast<target> (object);
		}
	}
%}

namespace Xern
{
	boost::shared_ptr<target> CastTo ## target(boost::shared_ptr<IInterface> object);
};

%enddef

CAST_TO(ICamera)
CAST_TO(IGeometry)
CAST_TO(IGeometryInstance)
CAST_TO(ILight)
CAST_TO(IMaterial)
CAST_TO(IMovableObject)
CAST_TO(IParticleSystem)
CAST_TO(IResource)
CAST_TO(ISoundSampler)
CAST_TO(ITexture)
